<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/style/vds.css" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/style/main.css" />
<link rel="stylesheet" type="text/css" href="public/theme/backend/style/goods.css" />
<script type="text/javascript" src="public/theme/backend/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="public/theme/backend/js/vds.js"></script>
<script type="text/javascript" src="public/theme/backend/js/juicer.js"></script>
<script type="text/javascript">
$(function(){
  getAttrs();
  $('#cate_id').change(function(){getAttrs();});
});

function getAttrs(){
  var cate_id = $('#cate_id').val(), goods_id = $('#goods_id').val();
  $.ajax({
    type: "post",
    dataType: "json",
    url: "<{url m=$MOD c='goods' a='edit' step='asyncgetattrs'}>",
    data: {'cate_id':cate_id, 'goods_id':goods_id},
    beforeSend: function(){loadingBar();},
    success: function(data){
      loadingBar('hide');
      $('#attrs').empty();
      if(data.status == 1){
        var attrhtml = juicer($('#attr-tpl').html(), data);
        $('#attrs').append(attrhtml);
      }else{
        $('body').vdsAlert({msg:"该分类未设置相关属性", time:1});
      }
    },
    error: function(){
      loadingBar('hide');
      $('body').vdsAlert({msg:"处理请求时发生错误", time:1});
    }
  });
}
</script>
</head>
<body>
<div class="content">
  <div class="loc"><h2><i class="icon"></i>商品属性规格:<font class="ml5">[<{$goods.goods_id}>]</font></h2></div>
  <div class="box">
    <div class="bw-row ta-c pad10 cut">
      <h3 class="c666"><{$goods.goods_name}></h3>
      <p class="c999 mt10">货号:<font class="c666 ml5"><{$goods.goods_sn}></font></p>
      <div class="ta-c mt10">
        <label><font class="c999 mr5">分类:</font>
        <select class="slt" id="cate_id">
          <option value="0">选择分类</option>
          <{foreach $cates as $v}> <{if $v.cate_id == $goods.cate_id}>
          <option value="<{$v.cate_id}>" selected="selected"><{str_repeat('|— ',$v.lv)}> <{$v.cate_name}></option>
          <{else}>
          <option value="<{$v.cate_id}>"><{str_repeat('|— ',$v.lv)}> <{$v.cate_name}></option>
          <{/if}>
	  <{/foreach}>
        </select>
        </label>
      </div>
    </div>
    <form method="post" action="<{url m=$MOD c='goods' a='edit' step='attr' do='update'}>">
      <input name="goods_id" type="hidden" id="goods_id" value="<{$goods.goods_id}>" />
      <div class="bw-row mt5 pad10">
        <div class="attrli x-auto" id="attrs"></div>
        <script type="text/template" id="attr-tpl">
          {@each attrs as v}
          <dl>
            <dt>${v.name}:<input name="attrs[id][]" type="hidden" value="${v.attr_id}" /></dt>
            {@if v.opts == ''}
            <dd><input class="w200 txt" name="attrs[value][]" type="text" value="${v.value}" /><font class="c999 ml5">${v.uom}</font></dd>
            {@else}
            <dd>
              <select name="attrs[value][]" class="slt">
              {@each v.opts as vv}<option value="${vv}" {@if v.value == vv}selected="selected"{@/if}>${vv}</option>{@/each}
              </select>
              <font class="c999 ml5">${v.uom}</font>
            </dd>
            {@/if}
          </dl>
          {@/each}
        </script>
      </div>
      <div class="mt10 pad10 ta-c"><button type="submit" class="ubtn btn">保存并更新</button></div>
    </form>
  </div>
</div>
</body>
</html>